package com.xiaobaibai.units;

import com.xiaobaibai.pojo.Comment;

import java.util.Comparator;
import java.util.Date;
import java.util.Map;

public class CommentSort implements Comparator<Comment> {

    private Map<Integer, Date> map;

    public CommentSort(Map<Integer, Date> map) {
        this.map = map;
    }

    @Override
    public int compare(Comment o1, Comment o2) {//负数->o1比o2小 正数反之  0相等
        Date date1=map.get(o1.getId());
        Date date2=map.get(o2.getId());
        if(date1.after(date2))
            return -1;//小的排前面,然而这里需要大的排前面
        return 1;
    }
}
